@using Orchard.ContentManagement;
@using Dyn.News.ViewModels;
@using System.Text;
@using Dyn.News.Models;
@{ 
    var widget = Model.WidgetVM as NewsCategoryMenuWidgetPart;
    var result = new StringBuilder();
    foreach (var item in widget.CategoryMenus)
    {
        result.Append(TreeView(item));
    }
    var tree = new HtmlString(result.ToString());
}
@functions {
    string TreeView(ContentCategoryMenuWidgetViewModel category)
    {
        string check = string.Empty;
        string display = string.Empty;
        if (category.IsEnable)
            check = "checked = 'checked'";
        else
            display = "style='display:none'";
        StringBuilder result = new StringBuilder();
        result.Append("<li>\r\n");
        if (category.Childs.Count > 0)
        {
            result.Append("<span class='folder'>");
        }
        else
        {
            result.Append("<span class='file'>");
        }
        result.Append("<div>");
        result.Append("<a href='"+category.CategoryUrl+"'>"+category.Name+"</a>");
        result.Append("</div>");
        result.Append("</span>");
        if (category.Childs.Count > 0)
        {
            result.Append("<ul>\r\n");
            var childs = category.Childs.OrderBy(c => c.DisplayOrder);
            foreach (var item in childs)
            {
                result.Append(TreeView(item));
            }
            result.Append("</ul>\r\n");
        }
        result.Append("</li>\r\n");
        return result.ToString();
    }
}
<fieldset>
    <div class="category-menu">
        <ul id="categorytree">
            @tree
        </ul>
    </div>
</fieldset>